<template>
  <div class="count">
    <h2>当前求和为：{{ sum }},放大10倍后的数据：{{ bigSum }}</h2>
    学校:{{ school }}
    处理后的学校: {{ upperSchool }}
    <select v-model.number="n">
      <option value="1">1</option>
      <option value="2">2</option>
      <option value="3">3</option>
    </select>
    <button @click="add">加</button>
    <button @click="minus">减</button>
  </div>
</template>

<script setup lang="ts" name="Count">
import {ref} from "vue";
import {useCountStore} from "@/store/Count.ts";
import {storeToRefs} from "pinia";

const countStore = useCountStore();
const {increment, decrement} = countStore
let {sum, school, bigSum, upperSchool} = storeToRefs(countStore)
countStore.$subscribe((mutation, state) => {
  console.log("里面谁发生了改变", mutation, state)
  localStorage.setItem('countList', JSON.stringify(state))
})

// 数据
let n = ref(1) // 用户选择的数字
// 方法
function add() {
  // 调用对应action
  increment(n.value)
}

function minus() {
  decrement(n.value)
}
</script>

<style scoped>
.count {
  background-color: skyblue;
  padding: 10px;
  border-radius: 10px;
  box-shadow: 0 0 10px;
}

select, button {
  margin: 0 5px;
  height: 25px;
}
</style>